package com.thh.design.sington;

/**
 * @ClassName Singleton
 * @Description 单例模式(延迟实例化)
 * @Author thh
 * @Date 19:28 2021/01/13
 **/
public class Singleton2 {

    private volatile static  Singleton2 single = null;

    private Singleton2(){ //构造方法私有化
    }

    public static Singleton2 getInstance(){
        //为了防止安全问题 以及保证效率  采用使用DCL双检查锁机制
        if (single == null){
            synchronized (Singleton.class){
                if (single == null){
                    single = new Singleton2();
                }
            }
        }
        return single;
    }
}
